package Pre.Work;

import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Stream;

public class Exam05 {
    //编写一个生日提醒程序，使用Map来存储人名和对应的生日日期。够根据日期提醒用户哪些人今天过生日？
    //如何筛选显⽰出最近七天过⽣⽇的⽤⼾
    public static void main(String[] args) {
        HashMap<String, Date> hashMap = new HashMap<>();
        hashMap.put("张三", new Date(123, 8, 15));
        hashMap.put("李四", new Date(123, 8, 15));
        hashMap.put("王五", new Date(123, 8, 11));
        hashMap.put("赵六", new Date(123, 8, 11));

        Date date = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        String localdate = dateFormat.format(date);
        System.out.println("今天是：" + localdate);

        Stream<Map.Entry<String, Date>> stream = hashMap.entrySet().stream();
        stream.forEach(entry -> {
            SimpleDateFormat entryDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            String entryDate = entryDateFormat.format(entry.getValue());
            if (Objects.equals(entryDate, localdate)) {
                System.out.println(entry.getKey() + ", 今天是你的生日哦！🎂🎂🎂🎂🎂");
            }
        });

        //获取未来七天的日期\
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.DAY_OF_YEAR, +7); // 最近七天的截止日期
        Date sevenDaysAgo = calendar.getTime();
        System.out.println(sevenDaysAgo);

        Stream<Map.Entry<String, Date>> stream1 = hashMap.entrySet().stream().sorted(new Comparator<Map.Entry<String, Date>>() {
            @Override
            public int compare(Map.Entry<String, Date> o1, Map.Entry<String, Date> o2) {
                SimpleDateFormat e1 = new SimpleDateFormat("yyyy-MM-dd");
                String date1 = e1.format(o1.getValue());
                String date2 = e1.format(o2.getValue());
                return date1.compareTo(date2);
            }
        });
        stream1.forEach(System.out::println);
//        stream1.forEach(entry -> {
//            SimpleDateFormat entryDateFormat = new SimpleDateFormat("yyyy-MM-dd");
//            String entryDate = entryDateFormat.format(entry.getValue());
//            if (){
//                System.out.println(entry.getKey() + ", 今天是你的生日哦！🎂🎂🎂🎂🎂");
//            }
//        });

        //=========================================
        HashMap<String, String> hashMap1 = new HashMap<>();
        hashMap1.put("小羊", "2023-09-20");
        hashMap1.put("小猪", "2023-09-19");
        hashMap1.put("小牛", "2019-09-11");
        hashMap1.put("小鸡", "2023-09-13");
        // 跟据日期提醒用户哪些人今天过生日？
        Set<Map.Entry<String, String>> entries = hashMap1.entrySet();
        //
//        Set<Map.Entry<String, String>> set = entries.stream().filter(v -> {
//            // v key "人名" value "日期字符串"
//            return DateUtils.isBirthToday(v.getValue());
//        }).collect(Collectors.toSet());
//        System.out.println(set);
        entries.stream().filter(v->Exam06.isBirthSevenDay(v.getValue())).forEach(e -> System.out.println(e));
    }
}
